﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FrienDev.BusinessRules;
using System.IO;

public partial class Controls_Activity_FeedBackReport : System.Web.UI.UserControl
{
    private string m_path, m_fileName;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["activityid"]))
        {
            int activityid = Convert.ToInt32(Request.QueryString["activityid"]);
            m_path = Server.MapPath("~\\Upload\\ActivityReport\\");
            m_fileName = activityid + ".rar";
            if (File.Exists(m_path + m_fileName))
            {
                bt_UploadFile.OnClientClick = "return confirm('您已经提交过活动报告，再次提交将覆盖掉之前提交的文件，确定继续上传么？')";
            }
            
        }
        bt_UploadFile.Click += new EventHandler(bt_UploadFile_Click);
    }

    void bt_UploadFile_Click(object sender, EventArgs e)
    {
        string fileExt = System.IO.Path.GetExtension(fu_Report.FileName).ToLower();
        if (fu_Report.HasFile && (fu_Report.FileBytes.Length < 10240000) && fileExt == ".rar")
        {
            if (!Directory.Exists(m_path))
            {
                Directory.CreateDirectory(m_path);
            }
            try
            {
                if (File.Exists(m_path + m_fileName))
                {
                    File.Delete(m_path + m_fileName);
                }
                this.fu_Report.SaveAs(m_path + m_fileName);
                Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "javascript:alert('上传文件成功');", true);
            }
            catch
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "javascript:alert('上传文件失败');", true);
            }
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "javascript:alert('文件类型不正确或文件大于10M');", true);
        }
    }
}
